package com.usian.behavior.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.behavior.LikesBehaviorControllerApi;
import com.usian.behavior.service.ApLikesBehaviorService;
import com.usian.model.behavior.ApLikesBehavior;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.user.dtos.LikesBehaviorDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/likes_behavior")
public class LikesBehaviorController implements LikesBehaviorControllerApi {

    @Autowired
    private ApLikesBehaviorService apLikesBehaviorService;

    /**
     * 记录用户点赞、取消点赞 行为
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/like")
    public ResponseResult like(@RequestBody LikesBehaviorDto dto) {
        return apLikesBehaviorService.like(dto);
    }

    /**
     * article 远程调用 查询用户点赞行为接口
     * @param entryId
     * @param articleId
     * @return
     */
    @Override
    @GetMapping("/findLike/{entryId}/{articleId}")
    public ApLikesBehavior findLike(@PathVariable Integer entryId,
                                    @PathVariable Long articleId) {
        ApLikesBehavior apLikesBehavior = apLikesBehaviorService.getOne(Wrappers.<ApLikesBehavior>lambdaQuery()
                .eq(ApLikesBehavior::getEntryId, entryId)
                .eq(ApLikesBehavior::getArticleId, articleId));
        return apLikesBehavior;
    }


}
